<?php
class loginMod extends base{
	public function index() {
			
		$this->display();
	}
	public function do_login(){
		
		$data = $_POST;
		
		$client=post_curl($data,'MEMBER_LOGIN');
	
		
		if($client['status']!=1){
			$this->error(lang::get($client['status']));
		}else{						

			$member = cp_encode($client['Msg'][0],cpConfig::get('authkey')); 
			if($_POST['remember']==1) {//记住密码保存30天
				cookie('member', $member,array('expire'=>2592000));				
			}else{//不记住密码
				cookie('member', $member);
			}
			$this->success('登录成功',url('member/index'));
		}
	}
	
	public function register(){
		$_SESSION['send_code'] = random(6,1);//用于手机发送
		$this->display();
	}
	public function do_register(){
		
		//短信验证
		if($_POST['Mobile']!=$_SESSION['mobile'] or $_POST['mobile_code']!=$_SESSION['mobile_code'] or empty($_POST['Mobile']) or empty($_POST['mobile_code'])){
			
			$this->error('手机验证码输入错误。');	
		}
		if($_POST['PassWord']!=$_POST['PassWord2']){
			$this->error('重复密码错误');
		}
		//接口		
		$data = $_POST;
		$data['IDTypeId']=1;//证件类型（int类型）1身份证
		$data['BP'] = 4; //业务入口（int类型）4网站 8微信
		unset($data['PassWord2']);
		$client=post_curl($data,'MEMBER_REG');
		if($client['status']!=1){
			$this->error(lang::get($client['status']));
		}else{

			$member = cp_encode($client['Msg'][0],cpConfig::get('authkey'));
			cookie('member', $member);
			$this->success('注册成功',url('member/index'));
		}
	}
	public function logout(){
		$_SESSION = array();
		cookie('member',null);
		$this->success('退出成功！',__APP__);
	}
	
	
	
	//找回密码
	public function forgetpad(){
		$_SESSION['send_code'] = random(6,1);//用于手机发送
		$this->display();
	}
	//找回密码处理
	public function do_forgetpad(){
		
		//短信验证
		if($_POST['Mobile']!=$_SESSION['mobile'] or $_POST['mobile_code']!=$_SESSION['mobile_code'] or empty($_POST['Mobile']) or empty($_POST['mobile_code'])){
			$this->error('手机验证码输入错误。');	
		}
		if($_POST['PassWord']!=$_POST['PassWord2']){
			$this->error('重复密码错误');
		}
		//接口	
		$data = array(
		'Mobile' => $_POST['Mobile'],//手机号
		'NewPassWord' => $_POST['PassWord'],//新密码
		);		
		$client=post_curl($data,'MEMBER_SET_PAD');
		if($client['status']!=1){
			$this->error(lang::get($client['status']));
		}else{
			
			$this->success('密码修改成功',url('login/index'));
		}
	}
}